????ࡱ> qsp9 R/bjbj2r+l    (<M)pLLLLLLL((((((($E+ e-P(LLLLL(LL)LLL(L(t:r'T(Ld Иwq^ '($)0M) (--(  HYPERLINK "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k/html/ppc_ingweb.asp" http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k/html/ppc_ingweb.asp Hosting .NET Web Services Get started in using the Winsock control to host Web Services as I walk you through the sample code attached to this article. Download  HYPERLINK "http://download.microsoft.com/download/pocketpc/ppcsmpl/8/W982KMeXP/EN-US/694-CF-DEV.exe" 694-CF-DEV.exe. What You Need  HYPERLINK "http://msdn.microsoft.com/library/default.asp?url=/downloads/list/pocket2002.asp" Microsoft eMbedded Visual Tools. A live Internet connection from your Pocket PC. To call Web Services from your PC, you can download  HYPERLINK "http://www.pocketsoap.com/pocketsoap/" Pocket SOAP (Simple Object Access Protocol). Gotchas The implementation to host Web Services using  HYPERLINK "http://www.w3.org/TR/2000/NOTE-SOAP-20000508/" SOAP in this article is very simplified and needs to be developed further to fully support any client accessing them. For example, the lack of a  HYPERLINK "http://www.w3.org/TR/wsdl" WSDL (Web Services Description Language) support prevents the Web Services from being called from  HYPERLINK "http://msdn.microsoft.com/library/default.asp?url=/downloads/list/websrv.asp" Microsoft SOAP Toolkit 2.0 and the beta versions of Microsoft Visual Studio .NET. Languages Supported English Why Host Web Services? In my previous article  HYPERLINK "http://msdn.microsoft.com/library/en-us/dnppc2k/html/ppc_soap.asp" Transfer Data the .NET Way, I provided samples for accessing Web Services (using SOAP) from the Pocket PC. That is probably the most common way that you will use Web Services on a Pocket PC because this is a great way to make the device the point of integration. The next logical step would be to also host those Web Services on your Pocket PC. You can probably think of more reasons than I can (don't hesitate to send me an e-mail if you do), but here are a few of my suggestions: Your personal calendar Web Service; that anyone (or probably your trusted friends) can call to check if you are available at a specific time and maybe even create an appointment with you. Your personal contacts Web Service; that can be called to extract contact information. Your current availability status Web Service; let's say you are a field service technician and your backoffice or even the customers want to check if you are available. In a local application, you could mark yourself as "online", "busy", "be right back", "away", "on the phone", "out to lunch", and so forth. Also, if you want to be able to do P2P (peer-to-peer) applications, you will need to both call and host Web Services on your Pocket PC. The number of P2P applications will increase rapidly as soon as we have this support on Pocket PCs. Some examples of P2P applications are: File Sharing: exchange files with friends directly without any need for a server. If you have your friend's ID (IP address), you could query her Pocket PC for available files (that she "published" by putting them in a certain folder) and then download the file to your Pocket PC. Messaging: chatting with your colleagues while on the go without any supporting server. You could even set up virtual meetings with several people without the need for a chat server. Gaming: imagine if you could connect directly with other players to play your favorite game together, wirelessly. Even if there are products that can provide similar functionality (like  HYPERLINK "http://www.odysseysoftware.com/viaxml_main.html" \t "new" Odyssey Software's ViaXML) already today, I haven't seen any that can publish Web Services using SOAP on the Pocket PC. I have therefore put together a sample that shows you how a simple Web Service (using SOAP) can be provided using Microsoft eMbedded Visual Basic. Sample Web Service When you run the sample application, it looks like this:  INCLUDEPICTURE "http://msdn.microsoft.com/library/en-us/dnppc2k/html/T_hostingweb1.gif" \* MERGEFORMATINET  Sample SOAP request and response.And in the above figure you can see that we have made a Web Service (SOAP) call from a client on another machine (a PC) using  HYPERLINK "http://www.pocketsoap.com/pocketsoap/" Pocket SOAP. Even if you are not familiar with SOAP, you can see in the request that a call is made to a method called Multiply with two parameters (a and b) with the values 3 (a) and 5 (b). In the response, the result is returned (15). And whatever number you provide with the request, the two numbers will get multiplied and returned. The really cool thing is that any client (PC, Pocket PC, mainframe, etc.) that can make a SOAP request, can now call your Pocket PC from anywhere in the world (provided you are connected to the Internet). Code Walkthrough The first thing you need to publish a Web Service is a Web server. You probably know that there is no Web server in a Pocket PC, and therefore we need to create one first. You can do that by using the Winsock control in eMbedded Visual Basic. If you add one to a form and name it wsoServer, you can use the following code to activate it on port 80, the port used for HTTP (Hypertext Transfer Protocol): Private Sub Form_Load() wsoServer.LocalPort = 80 wsoServer.Listen End Sub And as soon as a HTTP request comes in, you can accept it by: Private Sub wsoServer_ConnectionRequest() wsoServer.Accept End Sub The next thing to do, is to wait for the request to arrive and when it does, we can handle it like this: Private Sub wsoServer_DataArrival(ByVal bytesTotal As Long) Dim ls As String Dim lsHead As String Dim Params As Variant ' Get Request wsoServer.GetData ls txtRequest.Text = ls ' Parse Request ls = Mid(ls, InStr(ls, "<")) Params = SOAPParse(ls) ' Do Web Service ls = WebService(Params) ' Set Response ls = SOAPResponse(ls) ' Send Response lsHead = "HTTP/1.1 200 OK" & vbCrLf lsHead = lsHead & "Content-Length: " & CStr(Len(ls)) & vbCrLf ls = lsHead & vbCrLf & ls wsoServer.SendData ls txtResponse.Text = ls End Sub This event is called as soon as any data is received on the specified port that we listen to (in this case 80). We start by getting the data using the GetData method on the Winsock control. We output this data in the TextBox control (see figure above). We remove the HTTP header using the Mid function and then we parse the SOAP request into a Variant array using the SOAPParse function (see below). Then we call the WebService function that implements the functionality of our Web Service. A response is created using the SOAPResponse function and it is sent back to the client with a correct HTTP header. Also, the response is output in another TextBox control (see figure above). The implementation of the SOAPParse function looks like this: Public Function SOAPParse(ByVal Request As String) As Variant Dim loXMLDoc As DOMDocument Dim loNodeList As IXMLDOMNodeList Dim loErrXML As IXMLDOMParseError Dim lnodX As IXMLDOMNode Dim lnodY As IXMLDOMNode Dim i As Integer Dim Params() ' Create XML document Set loXMLDoc = CreateObject("Microsoft.XMLDOM") ' Load request data loXMLDoc.loadXML Request ' Get Method and Namespace Set lnodX = loXMLDoc.documentElement.childNodes(0).childNodes(0) psMethod = lnodX.baseName psNamespace = lnodX.namespaceURI ' Get Parameters Set loNodeList = loXMLDoc.documentElement.childNodes(0).childNodes(0).childNodes ReDim Params(1, loNodeList.length - 1) For i = 0 To loNodeList.length - 1 Set lnodX = loNodeList(i) Params(0, i) = lnodX.nodeName Params(1, i) = lnodX.Text Next 'i ' Return parameter array SOAPParse = Params End Function And you can see that we read the XML (Extensible Markup Language) using a XML DOM (Document Object Model) and turn it into a two-dimensional array containing the two passed parameters. In the (0, x) array elements, we place the parameter name and in the (1, x) array elements, we place the parameter value. The WebService function implementation looks like this: Private Function WebService(ByRef Params As Variant) As String WebService = CStr(CInt(Params(1, 0)) * CInt(Params(1, 1))) End Function This is the place where the two parameters are multiplied and the result is returned. The SOAPResponse function creates the SOAP response: Public Function SOAPResponse(ByVal Result As String) As String Dim lsResponse As String ' Set payload lsResponse = _ "" & vbCrLf & _ "" & vbCrLf & _ "" & vbCrLf & _ " " & vbCrLf & _ " " & Result & "" & vbCrLf & _ " " & vbCrLf & _ "" & vbCrLf & _ "" ' Return response SOAPResponse = lsResponse End Function And when the response is returned using the SendData method on the Winsock control, the following event gets called: Private Sub wsoServer_SendComplete() wsoServer.Close wsoServer.Listen End Sub Where we close the connection and restart the control to listen for new requests. Using  HYPERLINK "http://www.pocketsoap.com/pocketsoap/" Pocket SOAP the test client to test the Web Service that we have implemented looks like this: TestPocketPC Function TestPocketPC() dim x, soap, t ' Create objects set soap = CreateObject("PocketSOAP.Envelope") set t = CreateObject("PocketSOAP.HTTPTransport") ' Set Envelope soap.methodName = "Multiply" soap.URI = "urn:Foo" ' Set parameters soap.CreateParameter "a", "3" soap.CreateParameter "b", "5" ' Make Call t.Send "http://ipaq/", soap.serialize x = t.Receive soap.parse x ' Show result wscript.echo "Result = " & soap.Parameters.Item(0).Value End Function An important note here is that my Pocket PC have been associated with the name "ipaq" and there are several ways to do that. If your Pocket PC is logged on to a Microsoft Windows NT/Microsoft Windows 2000 network, the name of your Pocket PC can be used in the URL. And if not, you can add your Pocket PC's name to the Hosts file (located in the \WINNT\system32\drivers\etc folder on your PC). Implement Future Solutions Now You can be quite sure that this will be possible to do natively on Pocket PCs in the future. If you start thinking, or maybe even implementing, solutions that utilize this technology, you will be well prepared for the future. Even if the sample above is intentionally made very simple, you could extend it to create real-world Web Services solutions for Pocket PC. Conclusion You now have the power to both consume (in the articles mentioned above) as well as host Web Services on your Pocket PC. This power opens up numerous possibilities, especially regarding P2P applications, and you are the one that can make them come true lmndopUVvw?@CKyzHIpq/ 0 J K ! ; <  (  ·Ϯ··Ϯ···Ϯ·ϢϢ5CJOJQJ\aJCJOJQJaJ0JCJOJQJaJjCJOJQJUaJCJOJQJaJ6CJOJQJ]aJCJOJQJaJ0JjU jUo(@fzCK *   Qe & Fwdhdx[$^w & Fwdhdx[$^w & Fwdhdx[$^w/ G eq~6<89RSGZ&'( -r69 ,"###|$$$%''޽뱠0JCJaJ!B*CJOJPJQJ^JaJph6CJOJQJ]aJjCJOJQJUaJCJOJQJaJ0JCJOJQJaJjCJOJQJUaJCJOJQJaJ5CJOJQJ\aJ?] H P f !!$!7!!!!!!!":"D"G"b"w"z""#2$o$|$%G%b%c%s%%%&d&~&&&'6'Q'c's's''''''(L(^(q(y((g)t))))))**'*F*]*^*q******'''(y((())))g)`+, -y..//o(CJOJQJaJ0JCJOJQJaJjCJOJQJUaJ0JCJOJQJaJ5CJOJQJ\aJ**+++S+`+, -y../ 01h2P. A!7"7#7$7%S DyK ]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k/html/ppc_ingweb.aspyK http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k/html/ppc_ingweb.aspDd.  S Ahttp://msdn.microsoft.com/library/en-us/dnppc2k/html/T_hostingweb1.gifbwQj.[ks H-DnwQj.[ks HPNG  IHDRAzPLTE9AA9A9199AIA999AIIAAA1911A9  III1-1( 0bKGDH cmPPJCmp0712HsIDATx^]6uM.r$=2͌m)v5uܟx<ås߇+gh .g1^C +jmhn Ɓk36H ?~Dkxu|C ?6d_.eF_r` 8my@;S dkL ߀A~^?16lV b2IyIF#3 y宴q$!f/Q4 9h4BŪ~pכ6Cv"tXJal{rl26Ƙc[;Uؗ@"Y`I"ŊKTjJ,eH(m⺈A݈GnY}#/ 9-9![pk>dfPEzy'>27£c?9!De;BV~k-EW9{/QvQsQA_a7d JČ ߝbBPZZB? WCD1shC&FHWCiF`˦'@ -YuT"S,K'(_ȫPK- ;Ix}'ȚPoug2ҍFC? ,CcMshjT=-A]݊V#9f: }!e'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x1$B*KHOJPJQJ^Jph:b`: HTML CodeCJOJPJQJ^JaJe`" HTML PreformattedS 2( Px 4 #\'*.25@9-D1$M %B*CJKHOJPJQJ^JaJph+rfzCK* Q e ~ 6 GZ'( -Wjr,C[^n-EHZ  >?]HPf!$7:DGbwz2 o | !G!b!c!s!!!"d"~"""#6#Q#c#s#####'$L$^$q$y$$g%t%%%%%%&&'&F&]&^&q&&&&&&&'''S'`'( )y**+000000(0 0 0 0(0 0(00000 0 0 00 0 0 00 00000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 '/.17er!s'*//234568/0moUv?yHp/J ; 8R$%%+XXTXTXTXTXTXTXTXTCTXTXTCJ .6$-9TYi!28IOp/14@AC\by   ,EMQ\cmq$'35Ehx  =GJmq{   &*+/9BCdmpv      4 > A E F J K Q [ _ ` f !$!%!*!M!W!u!!!!!!!!!!!"!"("1"D"Y"_"h"n"s"y""""""""""###+#1#;#A#F#L#V#`#######3$I$N$]$`$p$g%s%}%%%%%%%%%&)&8&H&P&T&[&s&&&&&&&&&&&''&'5'I'''+qvCUYip/1\b69'4hx Jn '  A F !%!u!!!!!!!!!"("i"n"""""<#A#W#`#=$J$N$]$`$p$}%%%%%%%%)&8&H&P&s&&&&&&&&&''&'+333333333333333333333333333333333333333333333333333333333333y**+jack1D:\My Documents\p2p\Hosting .NET Web Services.docq4b<=/i*0g.+0\^`CJOJQJo(^`CJOJQJo(opp^p`CJOJQJo(@ @ ^@ `CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(PP^P`CJOJQJo(^`CJOJQJo(^`CJOJQJo(opp^p`CJOJQJo(@ @ ^@ `CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(PP^P`CJOJQJo(^`CJOJQJo(^`CJOJQJo(opp^p`CJOJQJo(@ @ ^@ `CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(PP^P`CJOJQJo(^`CJOJQJo(^`CJOJQJo(opp^p`CJOJQJo(@ @ ^@ `CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(^`CJOJQJo(PP^P`CJOJQJo(q4=/i*0g.+0NzXrӤTHHlSnբ1.H0DZ]`|*xjrxuRZ~æNN>T.~xf.j 02` $Jnzt:Ƹ0j '(+@|_X+P@UnknownGz Times New Roman5Symbol3& z Arial7&  VerdanaI& ?Arial Unicode MSC.e0}fԚPMingLiU?5 z Courier New;Wingdings qh\yf]yfK#L!?!),.:;?]}    " % & ' 2 t%00 0 0 00000013468:<>@BDOPQRTUVWZ\^ \]d([{  5 0 0 00000579;=?ACY[][77x2 ,2 http://msdnjackjackOh+'0p  , 8 DPX`h http://msdnttpjack//mackack Normal.dotjackl.d1ckMicrosoft Word 9.0@F#@\wq@ wqK#՜.+,D՜.+,8 hp|  1/L ,  http://msdn DT 8@ _PID_HLINKSA HUN!&http://www.pocketsoap.com/pocketsoap/UN&http://www.pocketsoap.com/pocketsoap/ 0http://www.odysseysoftware.com/viaxml_main.html*YBhttp://msdn.microsoft.com/library/en-us/dnppc2k/html/ppc_soap.aspPCMhttp://msdn.microsoft.com/library/default.asp?url=/downloads/list/websrv.aspCNhttp://www.w3.org/TR/wsdlH .http://www.w3.org/TR/2000/NOTE-SOAP-20000508/UN &http://www.pocketsoap.com/pocketsoap/CQQhttp://msdn.microsoft.com/library/default.asp?url=/downloads/list/pocket2002.asp NYhttp://download.microsoft.com/download/pocketpc/ppcsmpl/8/W982KMeXP/EN-US/694-CF-DEV.exe1]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k/html/ppc_ingweb.asp1Ghttp://msdn.microsoft.com/library/en-us/dnppc2k/html/T_hostingweb1.gif  !"#$%&'()*+,-./0123456789;<=>?@ABCDEFGHJKLMNOPQRSTUVWXYZ[\]^_abcdefgijklmnorRoot Entry F+wqtData :1TableI-WordDocument2rSummaryInformation(`DocumentSummaryInformation8hCompObjfObjectPool+wq+wq  FMicrosoft Word MSWordDocWord.Document.89q